JBoss Community Archive (Read Only)

Graphene 2

Location Strategies

It is a way to wire-up you tests with the elements from the tested page. Graphene indeed supports a @FindBy mechanism, well-known from WebDriver project. That means support for e.g. css, id, tagName and other default location strategies. Graphene adds some goodies to this mechanism, check out FindBy annotation page for more info.

@FindBy(id = "htmlIdOfTheElement")
private WebElement yourElement;

However, it lacks support for custom location strategies. Graphene comes with ability to extend it, and at the same time provides an actual extension: @FindByJQuery annotation, which brings JQuery selectors to your tests.

Extending the location strategy

To introduce own strategy, lets say for angular.js, one needs to simply:

Extend By class

Be inspired with ByJQuery class.

Implement LocationStrategy interface

An implementation can look like following snippet:

public static class AngularLocationStrategy implements LocationStrategy {

        @Override
        public ByAngular fromAnnotation(Annotation annotation) {
            FindByAngular findBy = (FindByAngular) annotation;
            return new ByAngular(findBy.value());
        }
    }

Introduce e.g. @FindByAngular annotation

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@ImplementsLocationStrategy(ByAngular.AngularLocationStrategy.class)
public @interface FindByAngular {

    String value();
}

Use it in the tests

@FindByAngular("modelProperty")
private WebElement foo;
JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-10 12:14:40 UTC, last content change 2013-09-06 16:50:07 UTC.